var express = require('express');
var router = express.Router();
const {User} = require('../models')
const {success,failure} = require('../util/requestResult')
const {NotFoundError,BadRequestError,UnauthorizedError} = require('../util/errors')

router.post('/',async function(req,res,next){
    try {
        console.log(req.session.account);
        res.clearCookie('account'); // 清除 cookie
        res.clearCookie('password'); // 清除 cookie
        req.session.destroy(err => {
            if (err) {
                console.error('Error destroying session:', err);
            }
            // 清除 cookie
            res.clearCookie('sessionid'); // 确保 cookie 名称正确
            success(res,'退出成功',{})
        });
         
    } catch (error) {
        failure(res,error)
    }

})

module.exports = router